package com.food.eat.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.ObjectOutput;

/**
 * @Author:RenPu
 * @Date: 2020/7/19 17:03
 * @Version: 1.0
 * @description:
 */
public class FoodResultJson {

    //定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    //响应业务状态码
    private Integer status;

    //响应消息
    private String msg;

    //响应数据
    private Object data;

    @JsonIgnore
    private String ok;

    public FoodResultJson() {
    }

    public FoodResultJson(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }


    public FoodResultJson(Object data) {
        this.status = 200;
        this.msg = "ok";
        this.data = data;
    }

    public FoodResultJson(Integer status, String msg, Object data, String ok) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.ok = ok;
    }

    public static FoodResultJson build(Integer status, String msg, Object data) {
        return new FoodResultJson(status, msg, data);
    }

    public static FoodResultJson build(Integer status, String msg, Object data, String ok) {
        return new FoodResultJson(status, msg, data, ok);
    }

    public static FoodResultJson ok() {
        return new FoodResultJson(null);
    }

    public static FoodResultJson ok(Object tt) {
        return new FoodResultJson(tt);
    }

    public static FoodResultJson errMsg(String msg) {
        return new FoodResultJson(500, msg, null);
    }

    public static FoodResultJson errMap(Object data) {
        return new FoodResultJson(501, "error", data);
    }

    public static FoodResultJson errTokenMsg(String msg) {
        return new FoodResultJson(502, msg, null);
    }


    public static FoodResultJson errorException(String msg) {
        return new FoodResultJson(503, msg, null);
    }

    public static FoodResultJson errorUserQQ(String msg) {
        return new FoodResultJson(504, msg, null);
    }

    public static ObjectMapper getMAPPER() {
        return MAPPER;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }
}
